package com.woniuxy.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.pojo.UserBan;
import com.woniuxy.pojo.dto.UserBanDTO;
import com.woniuxy.service.UserBanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userBan")
public class UserBanController {
    @Autowired
    UserBanService userBanService;
    @PostMapping("/getAllBannedUser/{pageNum}/{pageSize}")
    public ResponseEntity<?> getAllBannedUser(@PathVariable Integer pageNum,
                                              @PathVariable Integer pageSize,
                                              @RequestBody(required = false) UserBanDTO dto){

        Page<UserBan> userPage = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<UserBan> wrapper = Wrappers.lambdaQuery(UserBan.class).eq(UserBan::getStatus, 0);

        if(dto != null && dto.getUsername() != null && !dto.getUsername().equals("")){
            wrapper.eq(UserBan::getUsername,dto.getUsername());
        }
        if(dto != null && dto.getPhone() != null && !dto.getPhone().equals("")){
            wrapper.eq(UserBan::getPhone,dto.getPhone());
        }
        userBanService.page(userPage,wrapper);

        return ResponseEntity.ok(userPage);

    }

    @PostMapping("/cancelBan/{id}")
    public ResponseEntity<?> cancelBan(@PathVariable Long id){
        Boolean b = userBanService.cancelBan(id);
        return ResponseEntity.ok(b);
    }
    @PostMapping("/batchCancel")
    public ResponseEntity<?> batchCancel(@RequestBody List<Long> ids){
        Boolean b = userBanService.batchCancel(ids);
        return ResponseEntity.ok(b);
    }

    @PostMapping("/banRemPreUser")
    public ResponseEntity<?> banRemPreUser(@RequestBody List<Integer> ids){
        Boolean success = userBanService.banRemPreUser(ids);
        return ResponseEntity.ok(success);
    }
}
